package com.ruoyi.article.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.article.domain.Material;
import com.ruoyi.article.dtos.PageResult;
import com.ruoyi.article.dtos.Result;
import com.ruoyi.article.service.MaterialService;
import com.ruoyi.common.core.controller.BaseController;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 课程管理Controller
 * 
 * @author hyh
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/material")
@Api("素材管理")
public class MaterialController extends BaseController
{

    @Autowired
    private MaterialService materialService;


    @PostMapping("/upload_picture")
    @ApiOperation("素材图片上传")
    @ApiImplicitParam(name = "multipartFile", value = "图片文件", required = true, dataType = "__file")
    //上传图片
    public Result uploadPicture(MultipartFile multipartFile){


        return  materialService.uploadPicture(multipartFile);
    }


    @PutMapping("/upload_picture_status")
    @ApiOperation("修改素材图片状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "素材ID", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "is_submit", value = "提交状态(0-未提交,1-已提交)", required = true, dataType = "Integer", paramType = "query")
    })
    //修改素材图片状态
    public Result uploadPictureStatus(@RequestParam("id") Long id,@RequestParam("is_submit") Integer isSubmit){


        return  materialService.uploadPictureStatus(id,isSubmit);
    }


    @DeleteMapping("/delete_picture")
    @ApiOperation("删除图片")
    @ApiImplicitParam(name = "id", value = "素材ID", required = true, dataType = "Long", paramType = "query")
    //删除图片
    public Result deletePicture(@RequestParam("id") Long id){


        return  materialService.deletePicture(id);
    }

    @GetMapping("/listMaterials")
    @ApiOperation("展示素材信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "5", dataType = "int", paramType = "query")
    })
    public Result<PageResult> listMaterials(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize) {

        PageInfo<Material> pageInfo = materialService.listMaterials(pageNum, pageSize);

        PageResult pageResult = new PageResult();
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setRecords(pageInfo.getList());


        return Result.success(pageResult);
    }


    @GetMapping("/getPhotoUrl")
    @ApiOperation("获取素材图片")
    public Result getPhotoUrl(){

        return materialService.getPhotoUrl();

    }


}
